# make_paper_assets.py
import pathlib, shutil, json, pandas as pd, matplotlib.pyplot as plt

root = pathlib.Path(__file__).parent
out = root / "paper_assets"
out.mkdir(exist_ok=True)

# 1. 复制关键图表
shutil.copy("docs/fig_growth.png", out / "fig_4_1_growth.png")
shutil.copy("docs/fig_storage_compare.png", out / "fig_5_2_storage.png")
shutil.copy("docs/fig_benchmark.png", out / "fig_5_3_benchmark.png")

# 2. 生成表 5-2
with open("data/benchmark.json") as f:
    r = json.load(f)
table = pd.DataFrame([r])
table.to_csv(out / "table_5_2.csv", index=False)

# 3. 生成 Word 可直接粘贴的 LaTeX/文本表
latex = r"""
\begin{table}[H]
\centering
\caption{10 万条配置压测结果}
\begin{tabular}{ll}
\hline
指标 & 数值 \\ \hline
总区块 & """ + str(r['total_blocks']) + r""" \\
总耗时 (s) & """ + str(r['total_time_s']) + r""" \\
平均延迟 (ms) & """ + str(r['avg_latency_ms']) + r""" \\
峰值 TPS & """ + str(round(r['peak_tps']/1e6, 2)) + r""" M \\
存储大小 (MB) & """ + str(round(r['chain_size_bytes']/1024/1024, 2)) + r""" \\ \hline
\end{tabular}
\label{tab:benchmark}
\end{table}
"""
(out / "table_5_2_latex.tex").write_text(latex, encoding='utf-8')

print("✅ 论文素材已生成到 paper_assets/")